/**
 * Created by duwei on 2019/4/1.
 */
var ZiPai_ZongJieSuanJavaWindow = ZiPai_ZongJieSuanWindow.extend({
    /**
     * 初始化界面
     * @private
     */
    _initInfo: function () {
        var self = this;
        self.fenshu = "";
        self._setWanFa();
        self._setTime();
        self._setRoomId();
        self._setPlayers();
        self._setRowPos();
        self._setInfoText();
    },
    /**
     * 设置玩法名称
     * @private
     */
    _setWanFa: function () {
        var self = this;
        var wanfa = (self._data['map_id'] ? (gameData.mapId2Name(self._data['map_id'])):null);
        this._nodeList["root.title"].setVisible(wanfa);
        if (this._nodeList["root.title"]) {
            this._nodeList["root.title"].setString(wanfa);
        }
        this._nodeList["root.fenbei"].setVisible(false);
    },
    /**
     * 设置时间
     * @private
     */
    _setTime: function () {
        var self = this;
        this._nodeList["root.lb_ts"].setString(timestamp2time(self._data['ts']));
    },
    /**
     * 设置房间号/局数
     */
    _setRoomId: function () {
        var self = this;
        this._nodeList["root.txtRoomId"].setString('房号：' + gameData.roomId);
        this._nodeList["root.txtRounds"].setString('局数：' + self._data['cur_round'] + '/' + self._data['total_round']);
    },
    /**
     * 设置玩家数据
     * @private
     */
    _setPlayers: function () {
        var self = this;
        self.maxDianpao = 0;
        self.maxScore = 0;
        self.maxUid = 0;
        var players = self._data['players'];
        for (var i = 0; i < players.length; i++) {
            var player = players[i];
            if (self.maxScore < player['score']) {
                self.maxScore = player['score'];
            }
        }
        for (var i = 0; i < players.length; i++) {
            var player = players[i];
            var uid = player['uid'];
            var score = player['score'];
            var playerInfo = gameData.getPlayerInfoByUid(uid);
            self.fenshu = self.fenshu + playerInfo.nickname + ":" + score + "\n";
            self._setRowUnit(i, player);
        }
        for (; i < 4; i++) {
            var RowUnit = this._nodeList["root.rowWidth.row" + i];
            if (RowUnit) {
                RowUnit.setVisible(false);
            }
        }
    },
    /**
     * 设置分享文本
     * @private
     */
    _setInfoText: function () {
        var self = this;
        this._infoText = "";
        var map_id = self._data['Map_id'] || self._data['map_id'];
        var wanfa = (map_id ? ('玩法：' + gameData.mapId2Name(map_id)) : '玩法：');
        var endTime = "结束时间：" + timestamp2time(self._data['ts']);
        var dyjName = "大赢家:";
        var count = 0;
        for (var i = 0; i < self._data['players'].length; i++) {
            var player = self._data['players'][i];
            if(self.maxScore>0 && player['score'] == self.maxScore){
                var playerInfo = gameData.getPlayerInfoByUid(player['uid']);
                dyjName += count>0?(','+playerInfo['nickname']):playerInfo['nickname'];
                count++;
            }
        }
        this._infoText = this._infoText + wanfa + "\n" + endTime + "\n" + self.fenshu + (count>0?dyjName:"");
    },
});